package com.spy.system.controller;

import com.spy.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spy.common.annotation.Log;
import com.spy.common.core.controller.BaseController;
import com.spy.common.core.domain.AjaxResult;
import com.spy.common.enums.BusinessType;
import com.spy.system.domain.DishCategory;
import com.spy.system.service.IDishCategoryService;
import com.spy.common.utils.poi.ExcelUtil;
import com.spy.common.core.page.TableDataInfo;

/**
 * 菜单类别Controller
 *
 * @author ruoyi
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/system/category")
@Api(tags = "菜单类别相关接口")
public class DishCategoryController extends BaseController
{
    @Autowired
    private IDishCategoryService dishCategoryService;

/**
 * 查询菜单类别列表
 */
@PreAuthorize("@ss.hasPermi('system:category:list')")
@GetMapping("/list")
@ApiOperation("查询菜单类别列表")
    public TableDataInfo<DishCategory> list(@ApiParam(value = "菜单类别查询条件") DishCategory dishCategory)
    {
        startPage();
        List<DishCategory> list = dishCategoryService.selectDishCategoryList(dishCategory);
        return getDataTable(list);
    }


    /**
     * 获取菜单类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取菜单类别详细信息")
    public R<DishCategory> getInfo(@ApiParam(value = "菜单类别ID", required = true)
                                   @PathVariable("id") Long id)
    {
                return R.ok(dishCategoryService.selectDishCategoryById(id));
    }

    /**
     * 新增菜单类别
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "菜单类别", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增菜单类别")
    public AjaxResult add(@ApiParam(value = "菜单类别实体", required = true) @RequestBody DishCategory dishCategory)
    {
        return toAjax(dishCategoryService.insertDishCategory(dishCategory));
    }

    /**
     * 修改菜单类别
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "菜单类别", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改菜单类别")
    public AjaxResult edit(@ApiParam(value = "菜单类别实体", required = true)  @RequestBody DishCategory dishCategory)
    {
        return toAjax(dishCategoryService.updateDishCategory(dishCategory));
    }

    /**
     * 删除菜单类别
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "菜单类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除菜单类别")
    public AjaxResult remove(@ApiParam(value = "菜单类别ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(dishCategoryService.deleteDishCategoryByIds(ids));
    }
}